﻿using System;
using System.Net;
using System.Windows.Forms;
using Sword.Data;

namespace Sword.WorkBench
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //WebProxy proxy = WebProxy.GetDefaultProxy();//获取IE缺省设置
            //var x = WebRequest.GetSystemWebProxy().GetProxy(new Uri("http://gv4e3e5agv4e3e5a.com"));
            //var x1 = WebRequest.GetSystemWebProxy().GetProxy(new Uri("http://gv4e3e5agv4e3e5a.com"));

            //var data = new DBHandler().SaveRulesTest();

            Application.ApplicationExit += Application_ApplicationExit;
            Application.Run(new MainForm());
        }


        static void Application_ApplicationExit(object sender, EventArgs e)
        {
            if (Application.OpenForms == null || Application.OpenForms.Count == 0)
            {
                return;
            }
            for (int i = 0; i < Application.OpenForms.Count; i++)
            {
                bool compared = Application.OpenForms[i] is MainForm;
                if (compared) { continue; }
                var coreService = (Application.OpenForms[i] as MainForm).coreService;
                if (coreService != null)
                {
                    coreService.ShutDown();
                    break;
                }
            }

            if (Fiddler.FiddlerApplication.oProxy != null)
            {
                Fiddler.FiddlerApplication.oProxy.Detach();
            }
            Fiddler.URLMonInterop.ResetProxyInProcessToDefault();
            Fiddler.FiddlerApplication.Shutdown();
        }
    }
}
